#ifndef PATCHSYSTEM_H
#define PATCHSYSTEM_H
#include "StompedReality/Asset/PatchInfo.h"
#include "StompedReality/Core.h"
#include "StompedReality/Core/GameAccess.h"

namespace StompedReality
{
namespace Asset
{
class DLL_EXPORT PatchSystem : public StompedReality::GameAccess
{
 protected:

  StompedReality::Asset::PatchInfo* m_PatchList;
  int m_Capacity;

 public:

  //! \brief	Constructor.
  PatchSystem( );

  //! \brief	Destructor.
  ~PatchSystem( );

  //! \brief	Initialize.
  void Initialize ( int capacity );

  //! \brief	Patch info getter.
  const PatchInfo GetPatchInfo ( ID id );

  //! \brief	GL Patch binding info getter.
  const ID GetGLPatchBindingID ( ID id );

  //! \brief	Patch exists check.
  bool HasPatchInfo ( ID id );

  //! \brief	Parses patch infos from from json.
  void ParsePatch ( Json::Value& root );

  //! \brief	Reads textures from file.
  void ReadFromFile ( const char* fileName );

  //! \brief	Reads data.
  //!			Reads data from the json value. No changes if parsing fails.
  //! \param	root	The json value.
  //! \return	Success parsing.
  bool ParseConfig ( Json::Value& root );

 public:

  //! \brief	Creates a Quad as triangle strip.
  float* CalculateBufferRect ( int width, int height );

  //! \brief	Fills the texture UV in the data buffer.
  void UpdateUV ( float* buffer,
                  int textureWidth, int textureHeight,
                  int offsetX, int offsetY,
                  int width, int height );
};

}
}
#endif // PATCHMANAGER_H
